home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2001 May / may_2001.iso / intercd / root / Multimedia / ^DivX_Article / virtualdub / VirtualDub-source-1_4d / VideoSource.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-03-20  |  4.5 KB  |  172 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    Copyright (C) 1998-2001 Avery Lee
  3. //
  4. //    This program is free software; you can redistribute it and/or modify
  5. //    it under the terms of the GNU General Public License as published by
  6. //    the Free Software Foundation; either version 2 of the License, or
  7. //    (at your option) any later version.
  8. //
  9. //    This program is distributed in the hope that it will be useful,
  10. //    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. //    GNU General Public License for more details.
  13. //
  14. //    You should have received a copy of the GNU General Public License
  15. //    along with this program; if not, write to the Free Software
  16. //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. #ifndef f_VIDEOSOURCE_H
  19. #define f_VIDEOSOURCE_H
  20.  
  21. #include <windows.h>
  22. #include <vfw.h>
  23.  
  24. #include "DubSource.h"
  25.  
  26. class AVIStripeSystem;
  27. class AVIStripeIndexLookup;
  28. class IMJPEGDecoder;
  29. class IAVIReadHandler;
  30. class IAVIReadStream;
  31.  
  32. class VideoSource : public DubSource {
  33. protected:
  34.     HANDLE        hBufferObject;
  35.     LONG        lBufferOffset;
  36.     void        *lpvBuffer;
  37.     BITMAPINFOHEADER *bmihDecompressedFormat;
  38.     long        stream_desired_frame;
  39.     long        stream_current_frame;
  40.  
  41.     void *AllocFrameBuffer(long size);
  42.     void FreeFrameBuffer();
  43.  
  44.     VideoSource();
  45.  
  46. public:
  47.     enum {
  48.         IFMODE_NORMAL        =0,
  49.         IFMODE_SWAP            =1,
  50.         IFMODE_SPLIT1        =2,
  51.         IFMODE_SPLIT2        =3,
  52.         IFMODE_DISCARD1        =4,
  53.         IFMODE_DISCARD2        =5,
  54.     };
  55.  
  56.     virtual ~VideoSource();
  57.  
  58.     BITMAPINFOHEADER *getImageFormat() const {
  59.         return (BITMAPINFOHEADER *)getFormat();
  60.     }
  61.  
  62.     void *getFrameBuffer() {
  63.         return lpvBuffer;
  64.     }
  65.  
  66.     HANDLE getFrameBufferObject() {
  67.         return hBufferObject;
  68.     }
  69.  
  70.     LONG getFrameBufferOffset() {
  71.         return lBufferOffset;
  72.     }
  73.  
  74.     virtual bool setDecompressedFormat(int depth);
  75.     virtual bool setDecompressedFormat(BITMAPINFOHEADER *pbih);
  76.  
  77.     BITMAPINFOHEADER *getDecompressedFormat() {
  78.         return bmihDecompressedFormat;
  79.     }
  80.  
  81.     virtual void streamSetDesiredFrame(long frame_num);
  82.     virtual long streamGetNextRequiredFrame(BOOL *is_preroll);
  83.     virtual int    streamGetRequiredCount(long *pSize);
  84.     virtual void *streamGetFrame(void *inputBuffer, long data_len, BOOL is_key, BOOL is_preroll, long frame_num) = NULL;
  85.  
  86.     virtual void streamBegin(bool fRealTime);
  87.  
  88.     virtual void invalidateFrameBuffer();
  89.     virtual    BOOL isFrameBufferValid() = NULL;
  90.  
  91.     virtual void *getFrame(LONG frameNum) = NULL;
  92.  
  93.     virtual char getFrameTypeChar(long lFrameNum) = 0;
  94.  
  95.     virtual bool isKeyframeOnly();
  96.     virtual bool isType1();
  97. };
  98.  
  99. class VideoSourceAVI : public VideoSource {
  100. private:
  101.     IAVIReadHandler *pAVIFile;
  102.     IAVIReadStream *pAVIStream;
  103.     HIC            hicDecomp, hicDecomp2;
  104.     LONG        lLastFrame;
  105.     BITMAPINFOHEADER *bmihTemp;
  106.     BOOL        use_ICDecompressEx;
  107.  
  108.     AVIStripeSystem            *stripesys;
  109.     IAVIReadHandler            **stripe_files;
  110.     IAVIReadStream            **stripe_streams;
  111.     AVIStripeIndexLookup    *stripe_index;
  112.     int                        stripe_count;
  113.  
  114.     IMJPEGDecoder *mdec;
  115.     HBITMAP        hbmLame;
  116.     bool        fUseGDI;
  117.     bool        fAllKeyFrames;
  118.     bool        bIsType1;
  119.  
  120.     IAVIReadStream *format_stream;
  121.  
  122.     char        *key_flags;
  123.     bool        use_internal;
  124.     int            mjpeg_mode;
  125.     void        *mjpeg_reorder_buffer;
  126.     int            mjpeg_reorder_buffer_size;
  127.     long        *mjpeg_splits;
  128.     long        mjpeg_last;
  129.     long        mjpeg_last_size;
  130.     FOURCC        fccForceVideo;
  131.     FOURCC        fccForceVideoHandler;
  132.  
  133.     void _construct();
  134.     void _destruct();
  135.  
  136.     bool AttemptCodecNegotiation(BITMAPINFOHEADER *, bool);
  137.  
  138. public:
  139.     VideoSourceAVI(IAVIReadHandler *pAVI, AVIStripeSystem *stripesys=NULL, IAVIReadHandler **stripe_files=NULL, bool use_internal=false, int mjpeg_mode=0, FOURCC fccForceVideo=0, FOURCC fccForceVideoHandler=0);
  140.     ~VideoSourceAVI();
  141.  
  142.     void Reinit();
  143.     void redoKeyFlags();
  144.  
  145.     int _read(LONG lStart, LONG lCount, LPVOID lpBuffer, LONG cbBuffer, LONG *lBytesRead, LONG *lSamplesRead);
  146.     BOOL _isKey(LONG samp);
  147.     LONG nearestKey(LONG lSample);
  148.     LONG prevKey(LONG lSample);
  149.     LONG nextKey(LONG lSample);
  150.  
  151.     bool setDecompressedFormat(int depth);
  152.     bool setDecompressedFormat(BITMAPINFOHEADER *pbih);
  153.     void invalidateFrameBuffer();
  154.     BOOL isFrameBufferValid();
  155.     bool isStreaming();
  156.  
  157.     void streamBegin(bool fRealTime);
  158.     void *streamGetFrame(void *inputBuffer, long data_len, BOOL is_key, BOOL is_preroll, long frame_num);
  159.     void streamEnd();
  160.  
  161.     void *getFrame(LONG frameNum);
  162.  
  163.     HIC    getDecompressorHandle() const { return hicDecomp; }
  164.     bool isUsingInternalMJPEG() const { return !!mdec; }
  165.  
  166.     char getFrameTypeChar(long lFrameNum);
  167.     bool isKeyframeOnly();
  168.     bool isType1();
  169. };
  170.  
  171. #endif
  172.